{extend name="admin@public/base" /}

{block name="body"}


    <div class="layui-form" style="margin: 20px;">
        <form class="layui-form {$form.class|default=''}" method="post"
              action="">
            {foreach $data as $kdata =>$vdata}
            <fieldset class="layui-elem-field">
                <legend>{$kdata}</legend>
                <div class="layui-field-box">
                    {volist name="vdata" id="vv"}
                    {if condition="empty($vv['child'])"}
                    <input alt="{$vv.menu}" type="checkbox" name="menu[]" title="{$vv.title}" value="{$vv.menu}"
                           {:in_array($vv['menu'],$auth)?'checked':''}>
                    {else/}

                    <div class="layui-card">
                        <div class="layui-card-header">{$vv.title}</div>
                        <div class="layui-card-body">
                            {foreach $vv['child'] as $kkk =>$vvv}
                            <input alt="{$vvv.menu}" type="checkbox" name="menu[]" title="{$vvv.title}" {:in_array($vvv['menu'],$auth)?'checked':''}
                            value="{$vvv.menu}">
                            {/foreach}
                        </div>
                    </div>
                    {/if}
                    {/volist}

                </div>
            </fieldset>
            {/foreach}

            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <button class="layui-btn" lay-submit lay-filter="main_form">保存</button>
                </div>
            </div>
        </form>

    </div>

{/block}

{block name="js"}
<script>
    layui.use(['form', 'layedit', 'laydate', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        var upload = layui.upload;

        var form_lock = false;

        form.on('submit(main_form)', function (data) {
            if (form_lock) {
                return false;
            }
            form_lock = true;
            $(data.elem).addClass('layui-btn-disabled');
            var method = $(data.form).attr('method');
            var url = $(data.form).attr('action');


            var post_data = data.field;
            delete post_data["file"];
            delete post_data["image"];
            var fun;
            if (method == 'get') {
                fun = $.get;
            } else {
                fun = $.post;
            }
            fun(url, post_data, function (res) {
                ajax_result(res);
                if (!res.url) {
                    form_lock = false;
                    $(data.elem).removeClass('layui-btn-disabled');
                }
            });
            return false;
        });

    });
</script>

{/block}